package com.airclick.merchant.utils;

/**
 * 通用返回对象
 *
 * @author macro
 * @date 2019/4/19
 */
public class CommonResult<T>{


    /**
     * 状态码
     */
    private String status;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 数据封装
     */
    private T data;

    private long dataCount;

    protected CommonResult() {
    }

    protected CommonResult(String status, String msg, T data, long dataCount) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.dataCount = dataCount;
    }

    protected CommonResult(String status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> CommonResult<T> success(T data,long dataCount) {
        return new CommonResult<T>(com.airclick.merchant.utils.Constants.SUCCESS, com.airclick.merchant.utils.Constants.SUCCESS_MSG, data,dataCount);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(com.airclick.merchant.utils.Constants.SUCCESS, com.airclick.merchant.utils.Constants.SUCCESS_MSG, data);
    }
    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> CommonResult<T>   success(T data, String message, int dataCount) {
        return new CommonResult<T>(com.airclick.merchant.utils.Constants.SUCCESS, message, data,dataCount);
    }

    /**
     *
     * @param status
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> CommonResult<T> failed(String status,String msg) {
        return new CommonResult<T>(status, msg, null);
    }



    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<T>(com.airclick.merchant.utils.Constants.ERROR, message, null);
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed() {
        return failed(com.airclick.merchant.utils.Constants.FAIL_CODE);
    }

    /**
     * 参数验证失败返回结果
     */
    public static <T> CommonResult<T> validateFailed() {
        return failed(com.airclick.merchant.utils.Constants.FAIL_CODE);
    }



    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public long getDataCount() {
        return dataCount;
    }
}
